from sqlalchemy import Column, Integer, String, Boolean, JSON, ForeignKey, Text
from sqlalchemy.orm import relationship
from app.db.database import Base

class Form(Base):
    __tablename__ = "forms"
    
    id = Column(Integer, primary_key=True, index=True)
    activity_id = Column(Integer, ForeignKey("activities.id"))
    form_items = Column(JSON)  # 存储表单项列表
    
    activity = relationship("Activity", back_populates="form")
    submissions = relationship("FormSubmission", back_populates="form")

class FormSubmission(Base):
    __tablename__ = "form_submissions"
    
    id = Column(Integer, primary_key=True, index=True)
    form_id = Column(Integer, ForeignKey("forms.id"))
    user_id = Column(Integer, ForeignKey("users.id"))
    answers = Column(JSON)  # 存储答案列表
    
    form = relationship("Form", back_populates="submissions")
    user = relationship("User", back_populates="form_submissions") 